package com.smartthinking.dive;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class DatabaseTables {

	public static final String TABLE_POIS= "pois";
	public static final String TABLE_ESTADO = "estado";
	public static final String TABLE_CATEGORIAS = "categorias";
	public static final String TABLE_SUBCATEGORIAS = "subcategorias";
	public static final String TABLE_POIS_SUBCATEGORIAS = "pois_subcategorias";
	public static final String TABLE_EVENTOS = "eventos";
	public static final String TABLE_BANNERS = "banners";
	public static final String TABLE_PERFILES = "perfiles";
	public static final String TABLE_MODULOS = "modulos";
	public static final String TABLE_PERMISOS_MODULOS = "permisos_modulos";
	public static final String TABLE_POIS_ESTADOS = "pois_estados";
	public static final String TABLE_TELEFONO = "telefono";
	
	private static final String DATABASE_CREATE_POIS = "create table " + TABLE_POIS + 
			"(poi_idr integer NOT NULL, " +
			"poi_nombre character varying(255)," +
			"poi_lat TEXT," +
			"poi_lng TEXT, " +
			"poi_direccion character varying(255), " +
			"poi_colonia character varying(255)," +
			"poi_municipio character varying(255), " +
			"poi_cp character varying(255), " +
			"poi_telefono1 character varying(255), " +
			"poi_telefono2 character varying(255), " +
			"poi_telefono3 character varying(255), " +
			"poi_telefono4 character varying(255), " +
			"poi_mail character varying(255), " +
			"poi_www character varying(255), " +
			"poi_thumb character varying(255), " +
			"poi_horarios character varying(255), " +
			"poi_facebook character varying(255), " +
			"poi_twitter character varying(255), " +
			
			"poi_youtube character varying(255), " +
			"poi_mail2 character varying(255), " +
			"poi_skype character varying(255), " +
			
			"poi_pdf character varying(255), " +
			"poi_desc character varying(255), " +
			"edo_cve character varying(255), " +
			"poi_destacado character varying(255), " +
			"poi_descripcion character varying(255), " +
			"poi_activo character varying(255), " +
			"CONSTRAINT pkpois PRIMARY KEY (poi_idr ));";

		
		private static final String DATABASE_CREATE_ESTADO = "create table " + TABLE_ESTADO + 
			"(edo_cve integer NOT NULL, " +
			"edo_des character varying(255)," +
			"CONSTRAINT pkestado PRIMARY KEY (edo_cve ));";
		
		
		private static final String DATABASE_CREATE_CATEGORIAS = "create table " + TABLE_CATEGORIAS + 
				"(cat_cve integer NOT NULL, " +
				"cat_des character varying(255)," +
				"CONSTRAINT pkcategorias PRIMARY KEY (cat_cve ));";
		
		
		public static final String DATABASE_CREATE_SUBCATEGORIAS = "create table " + TABLE_SUBCATEGORIAS + 
				"(sub_cve integer NOT NULL, " +
				"cat_cve integer," +
				"sub_des character varying(255)," +
				"CONSTRAINT pksubcategorias PRIMARY KEY (sub_cve, cat_cve ));";
		
		
		public static final String DATABASE_CREATE_POIS_SUBCATEGORIAS = "create table " + TABLE_POIS_SUBCATEGORIAS + 
				"(poi_idr integer NOT NULL, " +
				"cat_cve integer," +
				"sub_cve integer," +
				"CONSTRAINT pksubcategorias PRIMARY KEY (sub_cve, cat_cve, poi_idr ));";
		
		public static final String DATABASE_CREATE_EVENTOS = "create table " + TABLE_EVENTOS + 
				"(eve_idr integer NOT NULL, " +
				"eve_nombre character varying(255)," +
				"eve_descripcion character varying(255), " +
				"eve_poster character varying(255)," +
				"eve_fec_ini character varying(255), " +
				"eve_fec_fin character varying(255), " +
//				"eve_plano character varying(255), " +
				"eve_lugar character varying(255), " +
				"eve_contacto character varying(255), " +
				"eve_contacto2 character varying(255), " +
				"eve_mail character varying(255), " +
				"eve_tel character varying(255), " +
				"eve_tel2 character varying(255), " +
				"eve_tel3 character varying(255), " +
				"eve_tel4 character varying(255), " +
				"eve_facebook character varying(255), " +
				"eve_twitter character varying(255), " +
//				"eve_youtube character varying(255), " +
//				"eve_linkedin character varying(255), " +
//				"eve_mail_preregistro character varying(255), " +
				"eve_www character varying(255), " +
//				"eve_orden character varying(255), " +
//				"eve_publicado character varying(255), " +
//				"eve_lugar_en character varying(255), " +
				"eve_proveedores character varying(255), " +
				"eve_hora_ini character varying(255), " +
				"eve_hora_fin character varying(255), " +
				"eve_lat character varying(255), " +
				"eve_lng character varying(255), " +
				"eve_pdf character varying(255), " +
				"eve_destacado character varying(255)," +
				"eve_activo character varying(255), " +
				"eve_direccion character varying(255), " +
				"eve_colonia character varying(255), " +
				"eve_municipio character varying(255), " +
				"eve_cp character varying(255), " +
				"edo_cve integer, " +
				"CONSTRAINT pkeventos PRIMARY KEY (eve_idr ));";
		
		
		public static final String DATABASE_CREATE_BANNERS = "create table " + TABLE_BANNERS + 
				"(ban_idr integer NOT NULL, " +
				"ban_tipo character varying(255)," +
				"ban_url character varying(255)," +
				"ban_timer character varying(255)," +
				"ban_tamano character varying(255)," +
				"ban_destino_url character varying(255)," +
				"ban_activo integer,"+
				"CONSTRAINT pkbanners PRIMARY KEY (ban_idr ));";
		
		
		public static final String DATABASE_CREATE_PERFILES = "create table " + TABLE_PERFILES + 
				"(per_idr integer NOT NULL, " +
				"per_nombre character varying(255)," +
				"CONSTRAINT pkperfiles PRIMARY KEY (per_idr ));";
		
		
		public static final String DATABASE_CREATE_MODULOS = "create table " + TABLE_MODULOS + 
				"(mod_idr integer NOT NULL, " +
				"mod_des character varying(255)," +
				"CONSTRAINT pkmodulos PRIMARY KEY (mod_idr, mod_des ));";
		
		
		public static final String DATABASE_CREATE_PERMISOS_MODULOS = "create table " + TABLE_PERMISOS_MODULOS + 
				"(per_idr integer NOT NULL, " +
				"mod_idr integer," +
				"CONSTRAINT pkpermisos_modulos PRIMARY KEY (per_idr, mod_idr ));";
		

		public static final String DATABASE_CREATE_POIS_ESTADOS = "create table " + TABLE_POIS_ESTADOS + 
				"(poi_idr integer NOT NULL, " +
				"edo_cve integer," +
				"CONSTRAINT pkpois_estados PRIMARY KEY (poi_idr, edo_cve ));";
		
		
		public static final String DATABASE_CREATE_TELEFONO = "create table " + TABLE_TELEFONO + 
				"(tel_num character varying(255) NOT NULL, " +
				"CONSTRAINT pktelefono PRIMARY KEY (tel_num));";
		
		
		public static void onCreate(SQLiteDatabase db) {
	    	db.execSQL(DATABASE_CREATE_POIS);
	    	db.execSQL(DATABASE_CREATE_ESTADO);
	    	db.execSQL(DATABASE_CREATE_CATEGORIAS);
	    	db.execSQL(DATABASE_CREATE_SUBCATEGORIAS);
	    	db.execSQL(DATABASE_CREATE_POIS_SUBCATEGORIAS);
	    	db.execSQL(DATABASE_CREATE_EVENTOS);
	    	db.execSQL(DATABASE_CREATE_BANNERS);
	    	db.execSQL(DATABASE_CREATE_PERFILES);
	    	db.execSQL(DATABASE_CREATE_MODULOS);
	    	db.execSQL(DATABASE_CREATE_PERMISOS_MODULOS);
	    	db.execSQL(DATABASE_CREATE_POIS_ESTADOS);
	    	db.execSQL(DATABASE_CREATE_TELEFONO);
	    }


		public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
		    Log.w(DatabaseTables.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data");
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_POIS);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_ESTADO);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_CATEGORIAS);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_SUBCATEGORIAS);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_POIS_SUBCATEGORIAS);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_EVENTOS);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_BANNERS);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_PERFILES);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_MODULOS);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_PERMISOS_MODULOS);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_POIS_ESTADOS);
		        database.execSQL("DROP TABLE IF EXISTS " + TABLE_TELEFONO);
		        onCreate(database);
		}
	
}
